﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

namespace ClientOverflow.DataTransferObjects
{
    /// <summary>
    /// Question class is a DTO representing a question in the server side. The question contains direct
    /// information such as title and content. In addition is holds data such as tags, answers, votes and the posting
    /// user.
    /// The class is decorated with [DataContract] attribute and the properties are decorated with
    /// [DataMember] attributes. Using the decorations the class is compatible as data transfer object
    /// in the WCF service.
    /// </summary>
    [DataContract]
    public class Question
    {
        public Question()
        {
            Tags = new List<Tag>();
        }

        [DataMember]
        public int ID { get; set; }

        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public string Content { get; set; }

        [DataMember]
        public List<Tag> Tags { get; set; }

        [DataMember]
        public List<Answer> Answers { get; set; }

        [DataMember]
        public int? CorrectAnswerID { get; set; }

        [DataMember]
        public List<Vote> UpVotes { get; set; }

        [DataMember]
        public List<Vote> DownVotes { get; set; }

        public bool Equals(Question other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.ID == ID;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Question)) return false;
            return Equals((Question) obj);
        }

        public override int GetHashCode()
        {
            return ID;
        }
    }
}